package test.udp.socket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPClient {
	public static void main(String args[]) {
		try {
			// 创建Socket
			DatagramSocket socket = new DatagramSocket();

			// 创建发送包
			InetAddress host = InetAddress.getByName("localhost");
			String msg = "hello, I'm client!";
			DatagramPacket sendPacket = new DatagramPacket(msg.getBytes(), msg
					.length(), host, 12345);

			// 发送数据
			socket.send(sendPacket);
		} catch (SocketException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
